﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 绘直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            Pen pen = new Pen(Color.Chocolate, 5F);
            //线条的风格
            //pen.DashStyle = DashStyle.Dot;
            float[] dashValues = { 5, 2, 15, 4 };
            pen.DashPattern = dashValues;

            //画直线，建坐标
            Point p1 = new Point(40, 50);
            Point p2 = new Point(120, 50);
            Point p3 = new Point(40, 180);
            Point p4 = new Point(40, 60);
            //绘制直线

            g.DrawLine(pen, p1, p2);
            g.DrawLine(pen, p3, p4);

        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Color.Chocolate, 5F);
            Size size = new Size(100, 80);
            Point startPoint = new Point(30, 60);
            Rectangle rect = new Rectangle(startPoint, size);
            g.DrawRectangle(pen, rect);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Color.Chocolate, 5F);
            g.DrawEllipse(pen, 90, 90, 100, 100);
        }

        private void btnSector_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            //Pen pen= new Pen(Color.OrangeRed, 10);
            SolidBrush bush = new SolidBrush(Color.Crimson);
            g.FillPie(bush, 50, 100, 200, 200, 45, 90);

            bush = new SolidBrush(Color.Red);
            g.FillPie(bush, 50, 100, 200, 200, 135, 90);

            bush = new SolidBrush(Color.Green);
            g.FillPie(bush, 50, 100, 200, 200, 225, 90);

            Color myColor = Color.FromArgb(255, 60, 200, 100);
            bush = new SolidBrush(myColor);
            g.FillPie(bush, 50, 100, 200, 200, 315, 90);
            //写字
            g.DrawString("嘿嘿嘿", new Font("微软雅黑", 14, FontStyle.Regular), Brushes.Aquamarine, new PointF(40, 350));


        }
        private int i = 0;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void btnCaptcha_Click(object sender, EventArgs e)
        {


        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        private void picValidCode_Click(object sender, EventArgs e)
        {

        }

        private void txtValidCode_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {
            label1.Text = ValidateCode.CreateVCode(4);

            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePicture(label1.Text), 0, ValidateCode.CreateVCodePicture(label1.Text).Length);
            //显示图片的文件流格式
            pb_vCode.Image = Image.FromStream(ms);
        }
    }
}



